import { BasicColumn, FormSchema } from '@/components/Table';
import { h } from 'vue';
import { Tooltip } from 'ant-design-vue';
import { useI18n } from '@/hooks/web/useI18n';
// import { useCurrencyStore } from '/@/store/modules/currency';
import dayjs from 'dayjs';
import { toTimezone } from '/@/utils/dateUtil';
import { virtualCurrency } from '/@/views/system/common/const';
import cdBlockCurrency from '/@/components-cd/block/cd-block-currency.vue';

const { t } = useI18n();

// const { getCurrencyList } = useCurrencyStore();

const setTooltip = (text) => {
  return h(
    Tooltip,
    {
      title: text,
    },
    () =>
      h(
        'div',
        {
          style: { whiteSpace: 'nowrap', textOverflow: 'ellipsis', overflow: 'hidden' },
        },
        text,
      ),
  );
};

export const schemas: FormSchema[] = [
  {
    field: 'currency_id',
    labelPrefix: t('business.common_currency'),
    labelPrefixWidth: 45,
    component: 'ApiSelect',
    defaultValue: '',
    componentProps: {
      api: async () => {
        // const outputArray: any = getCurrencyList;
        return [...[{ label: t('business.common_all'), value: '' }], ...virtualCurrency];
      },
      labelField: 'label',
      valueField: 'value',
      showIcon: true,
      getPopupContainer: () => document.body,
    },
    colProps: { xxl: 3, xl: 3, lg: 4, md: 5, sm: 6 },
  },
  {
    field: 'cash_type',
    labelPrefix: t('table.finance.finance_business_type'),
    labelPrefixWidth: 75,
    component: 'Input',
    colProps: { xxl: 6, xl: 6, lg: 6, md: 6, sm: 7 },
    slot: 'businessTypeModal',
  },
  // {
  //   field: 'start_time',
  //   component: 'DatePicker',
  //   labelPrefix: t('business.common_period_start'), //开始时间
  //   labelPrefixWidth: 75,
  //   colProps: { xxl: 6, xl: 6, lg: 6, md: 6, sm: 6 },
  //   slot: 'startDate',
  //   defaultValue: dayjs().subtract(2, 'day').startOf('day').toDate(),
  //   componentProps: {
  //     getPopupContainer: () => document.body,
  //   },
  // },
  // {
  //   field: 'end_time',
  //   component: 'DatePicker',
  //   labelPrefix: t('business.common_period_end'), //结束时间
  //   labelPrefixWidth: 75,
  //   colProps: { xxl: 6, xl: 6, lg: 6, md: 6, sm: 6 },
  //   slot: 'endDate',
  //   defaultValue: dayjs().endOf('day').toDate(),
  //   componentProps: {
  //     getPopupContainer: () => document.body,
  //   },
  // },
	{
    field: 'time',
    labelPrefix: t('business.time_limite'),
    labelPrefixWidth: 75,
    component: 'RangePicker',
    defaultValue: [dayjs().subtract(2, 'day').startOf('day').toDate(), dayjs().endOf('day').toDate()],
    componentProps: {
      format: 'YYYY-MM-DD',
      placeholder: [t('business.common_start_time'), t('business.common_end_time')],
      getPopupContainer: () => document.body,
    },
  },

  // {
  //   field: 'search_type',
  //   labelPrefix: '',
  //   labelPrefixWidth: 10,
  //   component: 'Select',
  //   componentProps: {
  //     allowClear: true,
  //     options: [
  //       { label: t('business.common_site_number'), value: 1 },
  //       { label: t('business.common_site_protocol'), value: 2 },
  //       { label: t('business.common_site_name'), value: 3 },
  //       { label: t('business.common_auditors'), value: 4 },
  //     ],
  //     getPopupContainer: () => document.body,
  //   },
  //   colProps: { xxl: 1, xl: 1, lg: 4, md: 5, sm: 6 },
  // },
  // {
  //   field: 'search_value',
  //   label: '',
  //   component: 'Input',
  //   colProps: { xxl: 2, xl: 2, lg: 4, md: 5, sm: 6 },
  //   componentProps: {},
  // },
];

export const columns: BasicColumn[] = [
  {
    title: t('table.system.system_table_header_site_name'), //站点名称
    dataIndex: 'site_name',
    minWidth: 80,
    // customRender: ({ record }) => {
    //   return setTooltip(record.site_name);
    // },
  },
  {
    title: t('business.common_site_number'), //站点编号
    dataIndex: 'site_code',
    minWidth: 80,
    // customRender: ({ record }) => {
    //   return setTooltip(record.site_code);
    // },
  },
  // {
  //   title: '站点编号',
  //   dataIndex: 'site_id',
  //   minWidth: 80,
  //   customRender: ({ record }) => {
  //     return setTooltip(record.site_id);
  //   },
  // },
  {
    title: '业务类型',
    dataIndex: 'business_type',
    minWidth: 80,
    customRender: ({ record }) => {
      // return setTooltip(record.business_type);
      return record.business_type;
    },
  },
  {
    title: '变更类型',
    dataIndex: 'cash_type',
    minWidth: 80,
    customRender: ({ record }) => {
      //return setTooltip(record.cash_type);
      return record.cash_type;
    },
  },
  {
    title: '变更币种',
    dataIndex: 'currency_name',
    minWidth: 80,
    // customRender: ({ record }) => {
    //   return setTooltip(record.currency_name);
    // },
    customRender: ({ record }) => h(cdBlockCurrency, { currencyName: record.currency_name }),
  },
  {
    title: '变更金额',
    dataIndex: 'amount',
    minWidth: 80,
    customRender: ({ record }) => {
      return record.amount;
      //return setTooltip(record.amount);
    },
  },
  {
    title: '变更前余额',
    dataIndex: 'before_amount',
    minWidth: 80,
    customRender: ({ record }) => {
      //return setTooltip(record.before_amount);
      return record.before_amount;
    },
  },
  {
    title: '变更后余额',
    dataIndex: 'after_amount',
    minWidth: 80,
    customRender: ({ record }) => {
      //return setTooltip(record.after_amount);
      return record.after_amount;
    },
  },
  {
    title: '提交时间',
    dataIndex: 'apply_at',
    minWidth: 80,
    customRender: ({ record }) => {
      return toTimezone(record.apply_at);
    },
  },
  {
    title: '变更时间',
    dataIndex: 'created_at',
    minWidth: 80,
    customRender: ({ record }) => {
      return toTimezone(record.created_at);
    },
  },
];
